import 'dart:convert';

class UserLoginEntity {
  UserLoginEntity({
    required this.userName,
    required this.passWord,
    required this.lastLogin,
    this.token,
    this.avatar,
    this.nickName,
  });

  final String userName;
  final String passWord;
  final DateTime? lastLogin;
  final String? token;
  final String? avatar;
  final String? nickName;

  static UserLoginEntity fromJson(Map<String, dynamic> json) {
    final lastLogin = json['lastLogin'] as int?;
    return UserLoginEntity(
      userName: json['userName'] as String,
      passWord: json['passWord'] as String,
      lastLogin: lastLogin != null ? DateTime.fromMillisecondsSinceEpoch(lastLogin) : null,
      token: json['token'] as String?,
      avatar: json['avatar'] as String?,
      nickName: json['nickName'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'userName': userName,
      'passWord': passWord,
      'lastLogin': lastLogin?.millisecondsSinceEpoch,
      'token': token,
      'avatar': avatar,
      'nickName': nickName,
    };
  }

  @override
  String toString() {
    return jsonEncode(this);
  }
}
